//
//  CMFindReportByUidParser.m
//  CreditManger
//
//  Created by chaiyanan on 15/11/9.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "CMFindReportByUidParser.h"
#import "CMFindReportByUidInfo.h"
#import "CMFindReportByUidItemInfo.h"
#import "CMFindReportByUidSummaryInfo.h"

@implementation CMFindReportByUidParser

-(ParserResult*)parseResponseDictionary:(NSDictionary *)responseDictionary
{
    LLog(@"responseDictionary:%@",responseDictionary);
    ParserResult* result=[[ParserResult alloc]init];
    NSNumber* codeObject=[responseDictionary objectForKey:Key_Code];
    if (codeObject)
    {
        NSInteger code = [codeObject integerValue];
        result.code = code;
        result.message = [responseDictionary objectForKey:Key_Msg];
        if (code == 0)
        {
            NSDictionary *dataDict = [responseDictionary objectForKey:Key_Data];
            if (dataDict&&[dataDict isKindOfClass:[NSDictionary class]])
            {
                CMFindReportByUidInfo *info = [[CMFindReportByUidInfo alloc]init];
                NSArray *dataAry = dataDict[Key_zxList];
                if (dataAry&&[dataAry isKindOfClass:[NSArray class]])
                {
                    NSMutableArray *dataMulAry = [NSMutableArray arrayWithCapacity:dataAry.count];
                    for (NSDictionary *dict in dataAry)
                    {
                        if (dict&&[dict isKindOfClass:[NSDictionary class]])
                        {
                            CMFindReportByUidItemInfo *itemInfo = [[CMFindReportByUidItemInfo alloc]init];
                            itemInfo.cardtype = [DataTypeTranslate numberToString:dict[Key_cardtype]];
                            itemInfo.source = [DataTypeTranslate numberToString:dict[Key_source]];
                            itemInfo.merry = [DataTypeTranslate numberToString:dict[Key_merry]];
                            itemInfo.cardno = [DataTypeTranslate stringToString:dict[Key_cardno]];
                            itemInfo.realname = [DataTypeTranslate stringToString:dict[Key_realname]];
                            itemInfo.loginName = [DataTypeTranslate stringToString:dict[Key_loginName]];
                            NSArray *summaryAry = dict[Key_summaryData];
                            if (summaryAry&&[summaryAry isKindOfClass:[NSArray class]])
                            {
                                NSMutableArray *summaryMulAry = [NSMutableArray arrayWithCapacity:summaryAry.count];
                                for (NSDictionary *summaryDict in summaryAry)
                                {
                                    CMFindReportByUidSummaryInfo *summaryInfo = [[CMFindReportByUidSummaryInfo alloc]init];
                                    if (summaryDict&&[summaryDict isKindOfClass:[NSDictionary class]])
                                    {
                                        summaryInfo.loginName = [DataTypeTranslate stringToString:summaryDict[Key_loginName]];
                                        summaryInfo.state = [DataTypeTranslate stringToString:summaryDict[Key_state]];
                                        summaryInfo.xinyNum = [DataTypeTranslate numberToString:summaryDict[Key_xinyNum]];
                                        summaryInfo.zhufNum = [DataTypeTranslate numberToString:summaryDict[Key_zhufNum]];
                                        summaryInfo.qitNum = [DataTypeTranslate numberToString:summaryDict[Key_qitNum]];
                                        summaryInfo.createTime = [DataTypeTranslate stringToString:summaryDict[Key_createTime]];
                                    }
                                    [summaryMulAry addObject:summaryInfo];
                        
                                }
                                itemInfo.summaryData = summaryMulAry;
                            }
                            else
                            {
                                itemInfo.summaryData = [NSArray array];
                            }
                            
                            [dataMulAry addObject:itemInfo];
                            
                        }
                        else
                        {
                            result.code=1;
                            result.message=@"服务器数据异常";
                            return result;
                        }
                    }
                    info.zxList = dataMulAry;
                    result.result = info;
                }
                else
                {
                    info.zxList = [NSArray array];
                    result.result = info;
                }
                
            }
            else
            {
                result.code=1;
                result.message=@"服务器数据异常";
            }
            
        }
        
    }
    else
    {
        result.code=1;
        result.message=@"服务器数据异常";
    }
    
    return result;
}


@end
